package com.tianzeculture.stagebao.activity.home.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.android.exoplayer.C;
import com.squareup.picasso.Picasso;
import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.activity.artist.ArtistActivity;
import com.tianzeculture.stagebao.bean.ArtistsBean;
import com.tianzeculture.stagebao.bean.ImageBean;
import com.tianzeculture.stagebao.util.Util;
import com.tianzeculture.stagebao.view.SqImageView;

import java.util.List;

import io.rong.imlib.IFwLogCallback;

import static com.tianzeculture.stagebao.net.base.AppBaseRestUsageV2.PICTURE_URL;

/**
 * Created by Administrator on 2018/5/29 0029.
 */

public class BestPushAdapter extends RecyclerView.Adapter<BestPushAdapter.RecyclerViewHolder> {
    Context context;
    List<ImageBean> artistsBeans;

    public BestPushAdapter(Context context, List<ImageBean> artistsBeans) {
        this.context = context;
        this.artistsBeans = artistsBeans;
    }

    @Override
    public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_talent, parent, false);
        return new RecyclerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerViewHolder holder, int position) {
        holder.setData(position);
    }

    @Override
    public int getItemCount() {
        return artistsBeans.size();
    }


    class RecyclerViewHolder extends RecyclerView.ViewHolder {

        ImageView ivArtists;
        TextView tvArtists;

        public RecyclerViewHolder(View itemView) {
            super(itemView);
            ivArtists = itemView.findViewById(R.id.ivArtists);
            tvArtists = itemView.findViewById(R.id.tvArtists);
        }

        public void setData(final int position) {
            ivArtists.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    context.startActivity(new Intent(context, ArtistActivity.class).putExtra("otherId", artistsBeans.get(position).getUserId()));
                }
            });
            tvArtists.setText(artistsBeans.get(position).getUser().getNickname() == null ? "" : artistsBeans.get(position).getUser().getNickname());
            String[] arr = artistsBeans.get(position).getPath().split(",");
            if (arr.length < 2)
                return;
            Glide.with(context).load(PICTURE_URL + arr[1]).placeholder(R.mipmap.test).error(R.mipmap.test).dontAnimate().into(ivArtists);
        }
//
//        SqImageView ivBestPush;
//
//        public RecyclerViewHolder(View itemView) {
//            super(itemView);
//            ivBestPush = itemView.findViewById(R.id.ivBestPush);
//        }
//
//        public void setData(final int position) {
//            String[] arr = artistsBeans.get(position).getPath().split(",");
//            Glide.with(context).load(PICTURE_URL + arr[1]).error(R.mipmap.test).into(ivBestPush);
//            ivBestPush.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    context.startActivity(new Intent(context, ArtistActivity.class).putExtra("otherId", artistsBeans.get(position).getUserId()));
//                }
//            });
//        }
    }
}